package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags="菜品分类相关接口")

public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @ApiOperation(value = "分类查询" )
    @GetMapping("/page")
    public Result<PageResult> page( CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation(value="菜品分类查询")
    @GetMapping("/list")
    public Result list(Integer type){
        log.info("菜品分类查询：{}",type);
        return Result.success(categoryService.list(type));
    }


    @ApiOperation(value="状态启动关闭")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status, Long id){
        log.info("状态启动关闭：{}",status);
        categoryService.startOrStop(status,id);
        return Result.success();
    }
    @ApiOperation(value="修改菜品")
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类：{}",categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }

    @ApiOperation("删除菜品")
    @DeleteMapping  // 使用路径变量{id}
    public Result deleteById( Long id){
        log.info("删除分类：{}", id);
        categoryService.deleteById(id);
        return Result.success();
    }

    @ApiOperation(value="新增菜名分类")
    @PostMapping
    public  Result saveCategory(@RequestBody CategoryDTO categoryDTO ){
        log.info("新增分类：{}",categoryDTO);
        categoryService.saveCategory(categoryDTO);
        return Result.success();
    }


}
